package com.future.taskdemo.k8s;

import io.kubernetes.client.openapi.models.V1Namespace;
import io.kubernetes.client.openapi.models.V1ObjectMeta;
import org.apache.commons.collections4.map.SingletonMap;

import javax.xml.bind.JAXBException;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;

public class HttpClient {
    public static void main(String[] args) throws IOException, JAXBException {
        String url = "http://localhost:8899/nandao-pc-api/create/namespace";

            String input = URLEncoder.encode(
                    "{\n" +
                            "\t\"apiVersion\":\"v1\",\n" +
                            "\t\"kind\":\"Namespace\",\n" +
                            "\t\"metadata\":{\"name\":\"test-namespace\",\"labels\":{\"name\":\"test-namespace\"}}\n" +
                            "}\n",
                    "UTF-8");

        V1Namespace namespace=new V1Namespace();
        namespace.setApiVersion("v1");
        namespace.setKind("Namespace");
        V1ObjectMeta objectMeta=new V1ObjectMeta();
        objectMeta.setName("test-namespace");
        HashMap<String, String> objectObjectHashMap = new HashMap<>();
        objectObjectHashMap.put("name","test-namespace");
        objectMeta.setLabels(objectObjectHashMap);
        namespace.setMetadata(objectMeta);

//        RestTemplate.postObject(url,namespace);
        RestTemplate.response(url,input);

    }

}
